using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;

namespace CSP.DataAccess.Mapping
{
    public class OrderMap : EntityTypeConfiguration<Order>
    {
        public OrderMap()
        {
            // Primary Key
            this.HasKey(t => t.OrderNumber);

            // Properties
            this.Property(t => t.OrderNumber)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.OrderUserName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ServiceUserName)
                .HasMaxLength(50);

            this.Property(t => t.ServiceTitle)
                .HasMaxLength(100);

            this.Property(t => t.Phone)
                .HasMaxLength(20);

            this.Property(t => t.Email)
                .HasMaxLength(50);

            this.Property(t => t.ContactedMan)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Address)
                .HasMaxLength(200);

            this.Property(t => t.Remark)
                .HasMaxLength(300);

            this.Property(t => t.LastModified)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8)
                .IsRowVersion();

            // Table & Column Mappings
            this.ToTable("Order");
            this.Property(t => t.OrderNumber).HasColumnName("OrderNumber");
            this.Property(t => t.OrderUserName).HasColumnName("OrderUserName");
            this.Property(t => t.ServiceUserName).HasColumnName("ServiceUserName");
            this.Property(t => t.ServiceInfoId).HasColumnName("ServiceInfoId");
            this.Property(t => t.ServiceTitle).HasColumnName("ServiceTitle");
            this.Property(t => t.TotalPrice).HasColumnName("TotalPrice");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.ContactedMan).HasColumnName("ContactedMan");
            this.Property(t => t.AppointmentDate).HasColumnName("AppointmentDate");
            this.Property(t => t.PaymentStatus).HasColumnName("PaymentStatus");
            this.Property(t => t.Address).HasColumnName("Address");
            this.Property(t => t.UnitCount).HasColumnName("UnitCount");
            this.Property(t => t.CooperationStartTime).HasColumnName("CooperationStartTime");
            this.Property(t => t.CooperationEndTime).HasColumnName("CooperationEndTime");
            this.Property(t => t.OrderConfirmDate).HasColumnName("OrderConfirmDate");
            this.Property(t => t.Remark).HasColumnName("Remark");
            this.Property(t => t.status).HasColumnName("status");
            this.Property(t => t.OrderTime).HasColumnName("OrderTime");
            this.Property(t => t.LastModified).HasColumnName("LastModified");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");

            // Relationships
            this.HasRequired(t => t.ServiceInfo)
                .WithMany(t => t.Orders)
                .HasForeignKey(d => d.ServiceInfoId);

        }
    }
}
